import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart';
import '../../../app_files.dart';
import 'action.dart';
import 'state.dart';

Widget buildView(
    PlanListViewState state, Dispatch dispatch, ViewService viewService) {
  int _suspensionHeight = 50;

  Widget _buildSusWidget(String susTag) {
    return Container(
      height: _suspensionHeight.toDouble(),
      padding: const EdgeInsets.only(left: 20),
      child: Row(
        children: [
          Text(
            '$susTag',
            style: TextThemeConfig.Font15WithBigColor22,
          ),
        ],
      ),
    );
  }

  Widget _buildListItem(int index) {
    PlanItemModel mModel = state.plans[index];
    String susTag = mModel.getSuspensionTag();

    return Column(
      children: <Widget>[
        Offstage(
          offstage: mModel.isShowSuspension != true,
          child: _buildSusWidget(susTag),
        ),
        MyInkWellWidget(
          child: Container(
            height: 55,
            margin: EdgeInsets.only(left: 20,right: 20),
            child: Row(
              children: [
                Image.asset(state.currentIndex == index
                    ? 'images/cricle_select.png'
                    : 'images/circle.png'),
                Padding(padding: EdgeInsets.only(left: 20)),
                Text(
                  mModel.planName,
                  style: TextThemeConfig.Font15WithColor22,
                ),
                Expanded(child: Container()),
                Text(
                  mModel.planType == '1' ? '居民' : '非居民',
                  style: TextThemeConfig.Font14WithMainColor,
                ),
              ],
            ),
            decoration: BoxDecoration(
              border:
              Border(bottom: BorderSide(color: ThemeConfig.separeColor)),
              color: Colors.white,
            ),
          ),
          onTap: () => dispatch(PlanListViewActionCreator.onTapIndex(index)),
        ),
      ],
    );
  }

  return Scaffold(
    appBar: myAppBar(viewService.context, title: '选择执行安检任务'),
    backgroundColor: Colors.white,
    body: state.plans == null
        ? MyLoadingWidget()
        : Column(
      children: [
        Expanded(
          child: CustomRefreshList(
            child: ListView.builder(
              itemBuilder: (BuildContext context, int index) {
                return _buildListItem(index);
              },
              itemCount: state.plans.length,
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
            ),
            refreshController: state.refreshController,
            onRefresh: (_) =>
                dispatch(PlanListViewActionCreator.onLoad()),
            currentPage: 1,
          ),
        ),
        SafeArea(
          child: Container(
            width: double.infinity,
            margin: EdgeInsets.only(left: 20, right: 20, bottom: 30),
            height: 50,
            decoration: BoxDecoration(
              color: ThemeConfig.mainColor,
              borderRadius: BorderRadius.all(Radius.circular(4)),
            ),
            child: InkWell(
              child: Center(
                child: Text(
                  '确定',
                  style: TextThemeConfig.Font16WithWhite,
                ),
              ),
              onTap: () => dispatch(PlanListViewActionCreator.onSubmit()),
            ),
          ),
        ),
      ],
    ),
  );
}
